//
//  SWString.swift
//  JGeneralExample
//
//  Created by 贾培军 on 2020/6/8.
//  Copyright © 2020 贾培军. All rights reserved.
//

import UIKit

extension NSString{
    open func boundingSize(_ size:CGSize, _ font:UIFont) -> CGSize {
        let attribute = [NSAttributedString.Key.font: font]
        let size = self.boundingRect(with: size, options:[
            .truncatesLastVisibleLine,
            .usesLineFragmentOrigin,
            .usesFontLeading
        ], attributes: attribute, context: nil).size
        return size
    }
}

extension String {
    public func boundingSize(_ size:CGSize, _ font:UIFont) -> CGSize {
        let str:NSString = self as NSString
        return str.boundingSize(size, font)
    }
}

extension Bundle{
    public class func groupBundle(for aClass: AnyClass) -> Bundle? {
        if let url = Bundle(for: aClass).url(forResource: "icon", withExtension: "bundle") {
            return Bundle(url: url)
        }
        return nil
    }
}
